var HOST = "https://minsu.zhxmcx.cn/Xcx/";

function XRKHttpGet(api, succ, fail) {
  var url = HOST + api;
  wx.request({
    url: url,
    method: 'GET',
    success: function (res) {
      console.log(url, res);
      if (res.statusCode == 200) {
        succ(res.data);
      }
      else {
        fail(res.data);
      }
    },
    fail: function (error) {
      console.log(url, error);
      fail(error);
    }
  })
}
function XRKHttpPost(api, para, succ, fail) {
  var url = HOST + api;
  wx.request({
    url: url,
    data: para,
    method: 'POST',
    header: {
      "content-type": "application/x-www-form-urlencoded"
    },
    success: function (res) {
      console.log(url, res);
      if (res.statusCode == 200) {
        succ(res.data);
      }
      else {
        fail(res.data);
      }
    },
    fail: function (error) {
      console.log(url, error);
      fail(error);
    }
  })
}

function showMsgDialog(msg, cb) {
  wx.showModal({
    content: msg,
    showCancel: false,
    confirmColor: '#23a3fb',
    success: cb
  })
}
function showLoading(title = '加载中') {
  wx.showLoading({
    "title": title,
    "mask": true
  })
}

function getIndex(para, succ, fail) {
  XRKHttpPost("Index/ad", para, succ, fail);
}
function getRule(para, succ, fail) {
  XRKHttpPost("Index/rule", para, succ, fail);
}
function login(para, succ, fail) {
  XRKHttpPost("Login/login", para, succ, fail);
}
function getGoodsList(para, succ, fail) {
  XRKHttpPost("Goods/goods_list", para, succ, fail);
}
function getSearchList(para, succ, fail) {
  XRKHttpPost("Goods/search_list", para, succ, fail);
}
function getGoodsDate(para, succ, fail) {
  XRKHttpPost("Goods/getGoodsDate", para, succ, fail);
}
function getGoodsDetail(para, succ, fail) {
  XRKHttpPost("Goods/goods_detail", para, succ, fail);
}
function checkGoodsDate(para, succ, fail) {
  XRKHttpPost("Goods/checkGoodsDate", para, succ, fail);
}
function setOrder(para, succ, fail) {
  XRKHttpPost("Cart/order_add", para, succ, fail);
}
function getOrderPrice(para, succ, fail) {
  XRKHttpPost("Cart/order_price", para, succ, fail);
}
function getAddrInfo(para, succ, fail) {
  XRKHttpPost("Cart/get_addr_info", para, succ, fail);
}
function getAddressList(para, succ, fail) {
  XRKHttpPost("User/addr_list", para, succ, fail);
}
function setAddAddress(para, succ, fail) {
  XRKHttpPost("User/addr_add", para, succ, fail);
}
function setDefaultAddress(para, succ, fail) {
  XRKHttpPost("User/addr_def", para, succ, fail);
}
function delAddress(para, succ, fail) {
  XRKHttpPost("User/addr_del", para, succ, fail);
}
function getAddressInfo(para, succ, fail) {
  XRKHttpPost("User/addr_info", para, succ, fail);
}
function setEditAddress(para, succ, fail) {
  XRKHttpPost("User/addr_edit", para, succ, fail);
}
function getOrderList(para, succ, fail) {
  XRKHttpPost("User/order_list", para, succ, fail);
}
function getOrderDetail(para, succ, fail) {
  XRKHttpPost("User/order_detail", para, succ, fail);
}
function orderDel(para, succ, fail) {
  XRKHttpPost("User/order_del", para, succ, fail);
}
function getMemberInfo(para, succ, fail) {
  XRKHttpPost("User/user_info", para, succ, fail);
}
function orderLive(para, succ, fail) {
  XRKHttpPost("User/order_live", para, succ, fail);
}
function noticeList(para, succ, fail) {
  XRKHttpPost("Index/notice_list", para, succ, fail);
}

function showMsgDialog(msg, cb) {
  wx.showModal({
    content: msg,
    showCancel: false,
    confirmColor: '#23a3fb',
    success: cb
  })
}
function showLoading(title = '加载中') {
  wx.showLoading({
    "title": title,
    "mask": true
  })
}
function showToast(title = '加载中') {
  wx.showToast({
    title:title,
    icon: 'none',
    duration: 2000
  })
}
function checkAuth(fun) {
  wx.getSetting({
    /*success(res) {
    }*/
    success: fun
  })
}
module.exports = {
  login: login,
  getRule: getRule,
  showToast: showToast,
  getIndex: getIndex,
  checkAuth: checkAuth,
  showMsgDialog: showMsgDialog,
  showLoading: showLoading,
  getGoodsList: getGoodsList,
  getSearchList: getSearchList,
  getGoodsDetail: getGoodsDetail,
  setOrder: setOrder,
  getAddrInfo: getAddrInfo,
  getAddressList: getAddressList,
  setAddAddress: setAddAddress,
  setDefaultAddress: setDefaultAddress,
  delAddress : delAddress,
  getAddressInfo: getAddressInfo,
  setEditAddress: setEditAddress,
  getOrderPrice: getOrderPrice,
  getOrderList: getOrderList,
  getGoodsDate: getGoodsDate,
  orderDel: orderDel,
  getOrderDetail: getOrderDetail,
  checkGoodsDate: checkGoodsDate,
  noticeList: noticeList,
  orderLive: orderLive,
  getMemberInfo: getMemberInfo
}